﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.b00_zjmxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void b00_zjmx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            b00_zjmxMgr mgr = new b00_zjmxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_b00_zjmx(e.Parameters[b00_zjmx_Filter.ParamPrefix]));
            IList<b00_zjmx> list = mgr.FindAllByPage_b00_zjmx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[b00_zjmx_Filter.ParamPrefix]);
            b00_zjmx_MainStore.DataSource = list;
            b00_zjmx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            b00_zjmxMgr mgr = new b00_zjmxMgr();
            RowSelectionModel sm = b00_zjmx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                b00_zjmx _b00_zjmx = new b00_zjmx();
                _b00_zjmx.fundid = int.Parse(row.RecordID);
                if (mgr.Del_b00_zjmx(_b00_zjmx))
                {
                    log.Debug("b00_zjmx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            b00_zjmx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            b00_zjmxMgr mgr = new b00_zjmxMgr();
            b00_zjmx _b00_zjmx = new b00_zjmx();
            if (Hid.Text.Length > 0)
                _b00_zjmx = mgr.FindById_b00_zjmx(int.Parse(Hid.Text));
            
			_b00_zjmx.areacode = Txtareacode.Text.Trim();
			_b00_zjmx.yearfen = Txtyearfen.Text.Trim();
			_b00_zjmx.raiseatub = Txtraiseatub.Text.Trim();
			_b00_zjmx.centeradj = Txtcenteradj.Text.Trim();
			_b00_zjmx.provinceadj = Txtprovinceadj.Text.Trim();
			_b00_zjmx.cityadj = Txtcityadj.Text.Trim();
			_b00_zjmx.countyadj = Txtcountyadj.Text.Trim();
			_b00_zjmx.townadj = Txttownadj.Text.Trim();
			_b00_zjmx.farmerpay = Txtfarmerpay.Text.Trim();
			_b00_zjmx.mzadj = Txtmzadj.Text.Trim();
			_b00_zjmx.collectadj = Txtcollectadj.Text.Trim();
			_b00_zjmx.otheradj = Txtotheradj.Text.Trim();
			_b00_zjmx.sumjy = Txtsumjy.Text.Trim();
			_b00_zjmx.doorjy = Txtdoorjy.Text.Trim();
			_b00_zjmx.hosjy = Txthosjy.Text.Trim();
			_b00_zjmx.bigilljy = Txtbigilljy.Text.Trim();
			_b00_zjmx.riskjy = Txtriskjy.Text.Trim();
			_b00_zjmx.yearjy = Txtyearjy.Text.Trim();
			_b00_zjmx.yeardoorjy = Txtyeardoorjy.Text.Trim();
			_b00_zjmx.yearbigjy = Txtyearbigjy.Text.Trim();
			_b00_zjmx.yearhosjy = Txtyearhosjy.Text.Trim();
			_b00_zjmx.yearriskjy = Txtyearriskjy.Text.Trim();
			_b00_zjmx.lastyearsum = Txtlastyearsum.Text.Trim();
			_b00_zjmx.yearoutsum = Txtyearoutsum.Text.Trim();
			_b00_zjmx.state = Txtstate.Text.Trim();
			_b00_zjmx.dqbm = Txtdqbm.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_b00_zjmx(_b00_zjmx);
            else
                isok = mgr.Add_b00_zjmx(_b00_zjmx);
            if (isok)
            {
                b00_zjmx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("b00_zjmx中执行了保存（插入或修改），并成功");
                b00_zjmx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}